import 'dart:io';

import 'package:hive/hive.dart';
import 'package:test2/model/map.dart';
import 'package:test2/util/PicUtil.dart';

part 'game.g.dart';

@HiveType(typeId: 1)
class Game extends HiveObject {
  @HiveField(0)
  String name;

  @HiveField(1)
  String pic;

  @HiveField(2)
  bool top;

  Game({required this.name, required this.pic, required this.top});

  void deletePic() {
    print("delete " + pic);

    File oldFile = File(PicUtil.picRootPath + pic);
    if (oldFile.existsSync()) {
      oldFile.delete();
    }
  }

  Future deleteSelf() async {
    deletePic();
    Box<MapC> box = await Hive.openBox<MapC>("game${key}");
    for (MapC item in box.values) {
      await item.deleteSelf();
    }
    
    await delete();
  }
}
